//
//  NYSubjectAnalysisTableViewController.m
//  NiuWaJiaoYu
//
//  Created by MinLison on 2018/1/5.
//  Copyright © 2018年 niuwaketang. All rights reserved.
//

#import "NYSubjectAnalysisTableViewController.h"
#import "NYSubjectTitleCell.h"
#import "NYSubjectAnswerCell.h"
#import "NYGoodSubjectActionCell.h"
#import "NYGoodAnalysisCell.h"
#import "NYGoodSubjectCorrectAnswerCell.h"
@interface NYSubjectAnalysisTableViewController ()

@end

@implementation NYSubjectAnalysisTableViewController

- (void)viewDidLoad
{
        [super viewDidLoad];
        [self loadData];
}
- (void)configNavigationBar:(BaseNavigationBar *)navigationBar
{
        [super configNavigationBar:navigationBar];
        self.title = @"查看解析";
}
- (void)loadData
{
        [self setLoading:YES animation:YES];
        [self configNimbus];
        [self configNimbusDataForMutableSections:self.subjectModel];
}
- (void)configNimbus
{
        [super configNimbus];
        [self.tableView registerClass:[UITableViewHeaderFooterView class] forHeaderFooterViewReuseIdentifier:[UITableViewHeaderFooterView className]];
}

- (void)configNimbusDataForMutableSections:(NYSubjectModel *)subjectObj
{
        [self.tableViewModel addSectionWithTitle:nil];
        /// 不需要要拷贝模型数据，作为每个题目的记录属性
        [self.tableViewModel addObject:[NICellObject objectWithCellClass:[NYSubjectTitleCell class] userInfo:subjectObj]];
        if (subjectObj.question_type != NYQuestionTypeFillBlanks) {
                [subjectObj.exercises_answer_arr enumerateObjectsUsingBlock:^(NSString * _Nonnull daanObj, NSUInteger daanIdx, BOOL * _Nonnull daanStop) {
                        /// 要拷贝模型数据，因为模型数据含有计算属性（只作为显示使用）
                        [self.tableViewModel addObject:[NICellObject objectWithCellClass:[NYSubjectAnswerCell class] userInfo:subjectObj.modelCopy]];
                }];
        }
        
        /// 要拷贝模型数据，因为模型数据含有计算属性（只作为显示使用）
        [self.tableViewModel addObject:[NICellObject objectWithCellClass:[NYGoodAnalysisCell class] userInfo:subjectObj.modelCopy]];
        [self.tableViewModel addObject:[NICellObject objectWithCellClass:[NYGoodSubjectCorrectAnswerCell class] userInfo:subjectObj.modelCopy]];
        [self.tableView reloadData];
        [self setSuccess];
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
        UITableViewHeaderFooterView *view = [tableView dequeueReusableHeaderFooterViewWithIdentifier:[UITableViewHeaderFooterView className]];
        view.contentView.backgroundColor = UIColorForBackground;
        return view;
}
+ (NYViewControllerNavigationBarType)navigationBarType
{
        return NYViewControllerNavigationBarTypeBlue;
}
@end
